
import { getToken } from '@/common/ts/utils'
import axios from 'axios'
import { Toast } from 'vant'
import router from '../router'
import store from '@/store'

axios.defaults.baseURL = process.env.VUE_APP_API_HOST
axios.defaults.withCredentials = true
axios.defaults.headers['X-Requested-With'] = 'XMLHttpRequest'
axios.defaults.headers['token'] = store.state.token || ''
axios.defaults.headers.post['Content-Type'] = 'application/json'

axios.interceptors.response.use(res => {

    if (typeof res.data !== 'object') {
        Toast.fail('服务端异常！')
        return Promise.reject(res)
    }
    if (res.data.status != 200) {
        if (res.data.data) {
            Toast.fail(res.data.data)
            console.log(res.data);
        }
        return Promise.reject(res.data)
    }

    return res.data
})

export default axios